/*******  interface javascript *******/

var saving = -1;

function wrapper_full (id) {
  if (saving == id) {
    alert('You have already save this story');
    return;
  } else {
    saving = id;
  }
  
  savefull(id, document.location);
  
  setTimeout('waittofade_full('+id+')', 1000);

}

function savefull(row, target) {
  // fade org number
  new Effect.FadeKeepSpace('diggs-strong-'+row);
  
  currdigs = parseInt($('diggs-strong-'+row).innerHTML);
  currdigs++;
  
  setTimeout('fadeInIncrement(\'diggs-strong-'+row+'\', '+currdigs+')', 999);
  
  // do ajax post
  xajax_processFavorit(row);
  
  return false;
}

function fadeInIncrement(target, count) {
  $(target).innerHTML = count;
  new Effect.AppearKeepSpace(target, { duration: 1});
}

function waittofade_full(id) {
  $('diglink'+id).innerHTML = "<span>已收藏</span>";
}

function searchboxFocus(){
	rstext = document.getElementById('rstext');
	roundsearch1 = document.getElementById('roundsearch');
	roundsearch1.className="searching";
	if(rstext.value=="搜索"){
	rstext.value="";
	}
}

function searchboxBlur(){
	roundsearch1.className="";
	if(rstext.value==""){
	rstext.value="搜索";
	}
}
function searchboxClick(){
	if(rstext.value=="搜索"){
	rstext.value="";
	}
}

function commentboxFocus(){
	captcha = document.getElementById('commentcaptcha');
	captcha.style.display = "inline";
}

/*******  for ajax script *******/

function enablebutton (button, button2, target)
{
	var string = target.value;
	button2.disabled = false;
	if (string.length > 0) {
		button.disabled = false;
	} else {
		button.disabled = true;
	}
}


function submitSignup()
{
	if(window.navigator.userAgent.indexOf("MSIE")>=1) {
		xajax.$('submitButton').disabled=true;
		xajax.$('submitButton').value="请稍候...";
	}
	xajax_processRegForm(xajax.getFormValues("signupForm"));
	return false;
}

function submitLogin()
{
	if(window.navigator.userAgent.indexOf("MSIE")>=1) {
		xajax.$('submitButton').disabled=true;
		xajax.$('submitButton').value="请稍候...";
	}
	xajax_processLoginForm(xajax.getFormValues("loginForm"));
	return false;
}

function submitPost()
{
	if(window.navigator.userAgent.indexOf("MSIE")>=1) {
		xajax.$('submit1').disabled=true;
		xajax.$('submit1').value="请稍候...";
	}
	xajax_processSubmitForm(xajax.getFormValues("submitform1"));
	return false;
}

function submitPost2()
{
	if(window.navigator.userAgent.indexOf("MSIE")>=1) {
		xajax.$('submit2').disabled=true;
		xajax.$('submit2').value="请稍候...";
	}
	xajax_processSubmitForm2(xajax.getFormValues("submitForm2"));
	return false;
}

function submitPost3()
{
	if(window.navigator.userAgent.indexOf("MSIE")>=1) {
		xajax.$('submit3').disabled=true;
		xajax.$('submit3').value="请稍候...";
	}
	xajax_processSubmitForm3(xajax.getFormValues("submitForm3"));
	return false;
}

function submitEditPost()
{
	if(window.navigator.userAgent.indexOf("MSIE")>=1) {
		xajax.$('submit1').disabled=true;
		xajax.$('submit1').value="请稍候...";
	}
	xajax_processEditPostForm(xajax.getFormValues("submitform1"));
	return false;
}

function confirmHide(id)
{
	if(confirm('确定隐藏该游记吗?'))
		return xajax_hidePost(id);
	return false;
}

function confirmHidePlan(id)
{
	if(confirm('确定隐藏该计划吗?'))
		return xajax_hidePlan(id);
	return false;
}

function confirmDeletePlan(id)
{
	if(confirm('确定删除该计划吗?'))
		return xajax_deletePlan(id);
	return false;
}

function confirmDraftPlan(id)
{
	if(confirm('确定将该计划标记为草稿吗?'))
		return xajax_draftPlan(id);
	return false;
}

function buryComment(id)
{
	if(confirm('确定隐藏该评论吗?'))
		return xajax_hideComment(id);
	return false;
}

function submitComment()
{
	if(window.navigator.userAgent.indexOf("MSIE")>=1) {
		xajax.$('submit1').disabled=true;
		xajax.$('submit1').value="请稍候...";
	}
	xajax_processCommentForm(xajax.getFormValues("submitForm1"));
	return false;
}

function confirmPromote(id)
{
	if(confirm('确定推选该游记到首页吗?'))
		return xajax_promotePost(id);
	return false;
}

function submitEditProfile()
{
	if(window.navigator.userAgent.indexOf("MSIE")>=1) {
		xajax.$('submit1').disabled=true;
		xajax.$('submit1').value="请稍候...";
	}
	xajax_processEditProfileForm(xajax.getFormValues("submitForm1"));
	return false;
}

function submitPlanItem(type,id)
{
	xajax_processSubmitPlanItem(xajax.getFormValues("submitform"+type+id));
	return false;
}

function submitAddPlace()
{
	xajax_processSubmitAddPlace(xajax.getFormValues("searchplaceform2"));
	return false;
}

// for searchBar
function searchBarOver(){
	placeq1 = document.getElementById('placeq');
	placeq1.className = "placeq2";
	placer1 = document.getElementById('placer');
	placer1.className = "placer2";
	placeimage1 = document.getElementById('placeimage');
	placeimage1.src = "tr-themes/default/img/search_button_hover.gif";
	placeimage1.className = "placeimage2";
}

function searchBarOut(){
	placeq1 = document.getElementById('placeq');
	placeq1.className = "placeq1";
	placer1 = document.getElementById('placer');
	placer1.className = "placer1";
	placeimage1 = document.getElementById('placeimage');
	placeimage1.src = "tr-themes/default/img/search_button_rest.gif";
	placeimage1.className = "placeimage1";
}

function searchBarOver2(){
	placeq1 = document.getElementById('placeq2');
	placeq1.className = "placeq2";
	placer1 = document.getElementById('placer2');
	placer1.className = "placer2";
	placeimage1 = document.getElementById('placeimage2');
	placeimage1.src = "tr-themes/default/img/search_button_hover_2.gif";
	placeimage1.className = "placeimage2";
}

function searchBarOut2(){
	placeq1 = document.getElementById('placeq2');
	placeq1.className = "placeq1";
	placer1 = document.getElementById('placer2');
	placer1.className = "placer1";
	placeimage1 = document.getElementById('placeimage2');
	placeimage1.src = "tr-themes/default/img/search_button_rest_2.gif";
	placeimage1.className = "placeimage1";
}

function searchBarOver3(){
	placeq1 = document.getElementById('placeq');
	placeq1.className = "placeq2";
	placer1 = document.getElementById('placer');
	placer1.className = "placer2";
	placeimage1 = document.getElementById('placeimage');
	placeimage1.src = "tr-themes/default/img/search_button_hover_3.gif";
	placeimage1.className = "placeimage2";
}

function searchBarOut3(){
	placeq1 = document.getElementById('placeq');
	placeq1.className = "placeq1";
	placer1 = document.getElementById('placer');
	placer1.className = "placer1";
	placeimage1 = document.getElementById('placeimage');
	placeimage1.src = "tr-themes/default/img/search_button_rest_3.gif";
	placeimage1.className = "placeimage1";
}

function searchBarAdd(place){
	placeq1 = document.getElementById('placeq');
	placeq1.value += place+' ';
}

function searchBarNewAdd(place){
	placeq1 = document.getElementById('placeq2');
	placeq1.value += place+' ';
}

function showBubble(e,title,tip){
	popup=document.getElementById('bubbleDiv');
	pointer=document.getElementById('bubblePointer');
	if(popup&&pointer){
		var c=[];c.push('<h1>'+title+'</h1>');c.push('<p>'+tip+'</p>');
		popup.innerHTML=c.join('');
		popup.style.visibility='visible';
		pointer.style.visibility='visible';
	}
	return false;
}

function hideBubble(){
	var popup=document.getElementById('bubbleDiv');
	if(popup){popup.style.visibility='hidden';}
	var pointer=document.getElementById('bubblePointer');
	if(pointer){pointer.style.visibility='hidden';}
	return false;
}

function moveBubble(e){
	popup=document.getElementById('bubbleDiv');
	pointer=document.getElementById('bubblePointer');
	if(popup&&pointer){
		e=(e)?e:window.event;
		var x=0;
		var y=0;
		if(e.clientX||e.clientY){
			var viewport=document.body;
			if(document.compatMode=='CSS1Compat'){
				viewport=document.documentElement;
			}
			x=e.clientX+viewport.scrollLeft;
			y=e.clientY+viewport.scrollTop;
		}
		else if(e.pageX||e.pageY)
			{x=e.pageX;y=e.pageY;}
		popup.style.left=x+'px';
		popup.style.top=y+25+'px';pointer.style.left=x+12+'px';
		pointer.style.top=y+10+'px';
	}
	return false;
}

function confirmDeleteTag(id)
{
	if(confirm('确定删除该tag?'))
		return xajax_saveDeleteTag(id);
	return false;
}

function confirmDeletePlace(id)
{
	if(confirm('确定删除该地点?'))
		return xajax_deletePlace(id);
	return false;
}